package com.qifenqian.turbot.module.model

import android.content.Context
import com.qifenqian.turbot.base.BaseModel
import com.qifenqian.turbot.module.contract.CommentContract
import com.qifenqian.turbot.module.entity.response.CommentEntity
import com.qifenqian.turbot.net.ModelCallback
import com.qifenqian.turbot.net.NetObserver

/**
 * @author H
 * @createTime 2018/12/28 14:06
 * @description
 * @see
 * @since
 */
class CommentModel(context: Context) : BaseModel(context), CommentContract.Model {

    override fun reply(commentId: Int, replyContent: String, replyUserCode: String, callback: ModelCallback<Nothing>) {
        mClient!!.reply(commentId, replyContent, replyUserCode)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getCommentList(page: Int, callback: ModelCallback<List<CommentEntity>>) {
        mClient!!.getCommentList(page)
                .subscribe(object : NetObserver<List<CommentEntity>>(mContext, true) {
                    override fun onSuccess(msg: String?, t: List<CommentEntity>?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }
}
